// AddIn.cpp : Implementation of CAddIn

#include "stdafx.h"
#include "AddIn.h"
#include "ComFramework.h"


// CAddIn

STDMETHODIMP CAddIn::InterfaceSupportsErrorInfo(REFIID riid)
{
	static const IID* arr[] = 
	{
		&__uuidof(IAddIn)
	};
	for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
	{
		if (InlineIsEqualGUID(*arr[i],riid))
			return S_OK;
	}

	return S_FALSE;
}

STDMETHODIMP CAddIn::SatelliteDLLPath(void)
{
	// TODO: Add your implementation code here

	return S_OK;
}

STDMETHODIMP CAddIn::get_Name(BSTR* pVal)
{
	// TODO: Add your implementation code here

	return S_OK;
}

STDMETHODIMP CAddIn::get_Description(BSTR* pVal)
{
	// TODO: Add your implementation code here

	return S_OK;
}

STDMETHODIMP CAddIn::get_Connected(VARIANT_BOOL* pVal)
{
	// TODO: Add your implementation code here

	return S_OK;
}

STDMETHODIMP CAddIn::get_ProgID(BSTR* pVal)
{
	// TODO: Add your implementation code here
	return S_OK;
}


HRESULT CAddIn::LoadAddIn()
{
	HRESULT hr = E_FAIL;

	SAF_TRY;

	hr = m_pExtensibility.CoCreateInstance(this->m_strProg);
	if (S_OK == hr)
	{
		m_bLoad = true;
		m_pExtensibility->OnConnection((IComFramework*)CComFramework::Instance(),	safConnectModeStartup,
									(interface_ptr)this, (LONG_PTR*)theApp->GetAddIns()->GetUserData());
	}else
	{
		//CStringW strError;
		//strError.FormatMessage(IDS_CREATE_COMBINATION_BODY_ERROR, 	this->m_strProg);
		//theApp->ComErrorBox(hr, (BSTR)(LPCTSTR)	this->m_strProg);
		//theApp->MsgBox(strError.AllocSysString(), MB_OK|MB_ICONERROR);
		//throw saf::CComException(hr, (BSTR)(LPCTSTR)	this->m_strProg);
		m_bLoad = false;
	}

	SAF_CATCH;

	return hr;
}

